import Vue from 'vue'
import Vuex from 'vuex'
import storage from '@/utils/storage'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: storage.getItem('token') || '',
    refresh_token: storage.getItem('refresh_token') || '',
    user: {} // 用户 - 基本资料
  },
  mutations: {
    setToken (state, token) {
      state.token = token
      storage.setItem('token', token)
    },
    refreshToken (state, refreshToken) {
      state.refresh_token = refreshToken
      storage.setItem('refresh_token', refreshToken)
    },
    setUser (state, user) {
      state.user = user
    },
    updatePhoto (state, photo) {
      state.user.photo = photo
    },
    updateName (state, name) {
      state.user.name = name
    }

  },
  actions: {
  },
  modules: {
  }
})
